package cn.edu.hit.kg;

import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public abstract class ScriptLoader {
    public static final String LASTEST = "lastest";
    protected ScriptEngine scriptEngine;
    private ScriptLoader parentLoader;

    public ScriptLoader(ScriptLoader parentLoader, ScriptEngine engine) {
        this.parentLoader = parentLoader;
        scriptEngine = engine;
    }

    public ScriptLoader(ScriptEngine scriptEngine) {
        this(null, scriptEngine);
    }

    public void loadUnit(String file) {
        try {
            InputStream inputStream = Neo4jConfigurationUtil.openFileStream(file);
            scriptEngine.eval(new BufferedReader(new InputStreamReader(inputStream)));
        } catch (ScriptException | IOException e) {
            e.printStackTrace();
        }
    }


}
